<?php

 

/*Define constant to connect to database */

DEFINE('DATABASE_USER', 'wargclub_root');
DEFINE('DATABASE_PASSWORD', '33205524rox');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'wargclub_gestion');
/*Default time zone ,to be able to send mail */
date_default_timezone_set('UTC');
 
/*You might not need this */
ini_set('SMTP', "mail.myt.mu");
// Overide The Default Php.ini settings for sending mail

 

//This is the address that will appear coming from ( Sender )

define('EMAIL', 'wargclub@gmail.com');

 

/*Define the root url where the script will be found such as

http://website.com or http://website.com/Folder/ */

DEFINE('WEBSITE_URL', 'http://174.120.153.93/~wargclub/');

 

// Make the connection:

$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD,

 DATABASE_NAME);

 

if (!$dbc) {

 trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());

}

 
?>

<?php
include ('global2.php');

if (isset($_POST['formsubmitted'])) {

    $error = array(); //Declare An Array to store any error message

    if (empty($_POST['name'])) { //if no name has been supplied

        $error[] = 'Please Enter a name '; //add to array "error"

    } else {

        $name = $_POST['name']; //else assign it a variable

  }

 

    if (empty($_POST['e-mail'])) {

        $error[] = 'Please Enter your Email ';

    } else {

 

        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",

            $_POST['e-mail'])) {

            //regular expression for email validation

            $Email = $_POST['e-mail'];

        } else {

            $error[] = 'Your EMail Address is invalid  ';

        }

 

    }

 

    if (empty($_POST['Password'])) {

        $error[] = 'Please Enter Your Password ';

    } else {

        $Password = $_POST['Password'];

    }

    if (empty($error)) //send to Database if there's no error '

 

    { // If everything's OK...

 

        // Make sure the email address is available:

        $query_verify_email = "SELECT * FROM members  WHERE Email ='$Email'";

        $result_verify_email = mysqli_query($dbc, $query_verify_email);

        if (!$result_verify_email) { //if the Query Failed ,similar to if($result_verify_email==false)

            echo ' Database Error Occured ';

        }

 

        if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .

 

            // Create a unique  activation code:

            $activation = md5(uniqid(rand(), true));

 

            $query_insert_user =

                "INSERT INTO `members` ( `Username`, `Email`, `Password`, `Activation`) VALUES ( '$name', '$Email', '$Password', '$activation')";

 

            $result_insert_user = mysqli_query($dbc, $query_insert_user);

            if (!$result_insert_user) {

                echo 'Query Failed ';

            }

 

            if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.

 

                // Send the email:

                $message = " To activate your account, please click on this link:\n\n";

                $message .= WEBSITE_URL . 'activate.php?email=' . urlencode($Email) . "&key=$activation";

                mail($Email, 'Registration Confirmation', $message, 'From:'.EMAIL);

 

                // Flush the buffered output.

 

                // Finish the page:

                echo '<div class="success">Thank you for registering! A confirmation email has been sent to ' . $Email .' Please click on the Activation Link to Activate your account </div>';

 
            } else { // If it did not run OK.

                echo '<div class="errormsgbox">You could not be registered due to a systemerror. We apologize for any inconvenience.</div>';

            }

 

        } else { // The email address is not available.

            echo '<div class="errormsgbox" >That email address has already been registered.

</div>';

        }

 

    } else { //If the "error" array contains error msg , display them

 

        echo '<div class="errormsgbox"> <ol>';

        foreach ($error as $key => $values) {

 

            echo '  <li>' . $values . '</li>';

 

        }
      
        echo '</ol></div>';

 

    }

 
    mysqli_close($dbc); //Close the DB Connection


} // End of the main Submit conditional.

?>











<form action="homee.php" method="post" class="registration_form">
  <fieldset>
    <legend>Registration Form </legend>
 
    <p>Create A new Account <span style="background:#EAEAEA none repeat scroll 0 0;line-height:1;margin-left:210px;;padding:5px 7px;">
Already a member? <a href="login.php">Log in</a></span> </p>
 

    <div class="elements">

      <label for="name">Name :</label>

      <input type="text" id="name" name="name" size="25" />

    </div>
    
    <div class="elements">

      <label for="e-mail">E-mail :</label>

      <input type="text" id="e-mail" name="e-mail" size="25" />

    </div>

    <div class="elements">

      <label for="Password">Password:</label>

      <input type="password" id="Password" name="Password" size="25" />

    </div>

    <div class="submit">

     <input type="hidden" name="formsubmitted" value="TRUE" />

      <input type="submit" value="Register" />

    </div>

  </fieldset>

</form>


<?php
